<template>
	<div class="goodsShelvesstyle">
		<h2>{{ datas.text }}</h2>
		<el-tabs type="border-card" :stretch="true">
			<el-tab-pane label="内容">
				<div class="decorate-card">
					<el-form label-width="80px" :model="datas">
						<div class="title">选择商品</div>
						<div>
							<div class="content">
								<div class="sd-flex sd-flex-wrap">
									<div class="goods-item" v-for="(item, index) in datas.goodsList" :key="index">
										<div class="sd-image sd-flex" style="width: 44px; height: 44px; border-radius: 4px">
											<el-image :src="STATIC_URL + item.image" fit="contain" class="image" />
										</div>
										<div class="goods-delete" @click="deleteItem(index)">
											<SvgIcon name="ele-DeleteFilled"></SvgIcon>
										</div>
									</div>
								</div>
							</div>
							<!-- 上传商品 -->
							<el-button @click="openItemDialog" class="uploadImg" type="primary" plain>点击添加商品</el-button>
						</div>

						<div class="title">商品样式</div>
						<el-form-item label="商品风格">
							<el-radio-group v-model="datas.mode">
								<!-- works when <2.6.0, deprecated act as value when >=3.0.0 -->
								<el-radio-button :label="1">
									<template #default>
										<span class="icon my-icon icon-shangxiabuju"></span>
									</template>
								</el-radio-button>
								<el-radio-button :label="2">
									<template #default><span class="icon my-icon icon-zuoyoujiegou"></span></template>
								</el-radio-button>
								<el-radio-button :label="3">
									<template #default><span class="icon my-icon icon-zuoyoujiegou"></span></template>
								</el-radio-button>
							</el-radio-group>
						</el-form-item>

						<el-form-item class="lef" label="商品标题">
							<el-input v-model="datas.goodsFields.title.color">
								<template #prepend>
									<el-color-picker v-model="datas.goodsFields.title.color" />
								</template>
								<template #append>
									<el-checkbox style="margin-left: 196px" v-model="datas.goodsFields.title.show" />
								</template>
							</el-input>
						</el-form-item>
						<el-form-item class="lef" label="商品价格">
							<el-input v-model="datas.goodsFields.price.color">
								<template #prepend>
									<el-color-picker v-model="datas.goodsFields.price.color" />
								</template>
								<template #append>
									<el-checkbox style="margin-left: 196px" v-model="datas.goodsFields.price.show" />
								</template>
							</el-input>
						</el-form-item>

						<div class="title">商品角标</div>

						<el-form-item label="角标选择">
							<el-radio-group v-model="datas.tagStyle.show">
								<el-radio :label="0">不显示</el-radio>
								<el-radio :label="1">显示</el-radio>
							</el-radio-group>
						</el-form-item>
						<el-form-item label="上传图片" v-if="datas.tagStyle.show == 1">
							<div class="choice-image choice-image-delete" @click="openChoiceFileImage">
								<el-image v-if="datas.tagStyle.src != ''" :src="STATIC_URL + datas.tagStyle.src" fit="contain" />
								<el-icon v-else>
									<Plus />
								</el-icon>
								<div class="delete-content" @click.stop="datas.tagStyle.src = ''" v-if="datas.tagStyle.src != ''">
									<SvgIcon name="ele-DeleteFilled"></SvgIcon>
								</div>
							</div>
						</el-form-item>
						<div class="title">样式</div>
						<el-form-item label="上圆角">
							<div class="flex">
								<el-slider class="ml20" v-model="datas.borderRadiusTop" />
								<el-input class="ml20" v-model="datas.borderRadiusTop"></el-input>
							</div>
						</el-form-item>
						<el-form-item label="下圆角">
							<div class="flex">
								<el-slider class="ml20" v-model="datas.borderRadiusBottom" />
								<el-input class="ml20" v-model="datas.borderRadiusBottom"></el-input>
							</div>
						</el-form-item>
						<el-form-item label="间距">
							<div class="flex">
								<el-slider class="ml20" v-model="datas.space" />
								<el-input class="ml20" v-model="datas.space"></el-input>
							</div>
						</el-form-item>
					</el-form>
				</div>
			</el-tab-pane>
			<el-tab-pane label="样式">
				<DataStyle :datas="datas.dataStyle"></DataStyle>
			</el-tab-pane>
			<el-tab-pane label="数据">
				<StyleComponentData :datas="datas"></StyleComponentData>
			</el-tab-pane>
		</el-tabs>

		<FileChoice ref="FileChoiceRef" @choiceFile="choiceFile"></FileChoice>

		<ItemChoice ref="ItemChoiceRef" @choice="choiceItem"></ItemChoice>
	</div>
</template>

<script setup lang="ts" name="goodsShelvesstyle">
import { ref, defineAsyncComponent } from 'vue';
import { Delete, Plus } from '@element-plus/icons-vue';
import vuedraggable from 'vuedraggable'; //拖拽组件
import { STATIC_URL } from '/@/utils/config';
const FileChoice = defineAsyncComponent(() => import('/@/views/file/choice/index.vue'));
const ItemChoice = defineAsyncComponent(() => import('/@/views/goods/goods/choice/index.vue'));
const props = defineProps({
	datas: {},
});

const ItemChoiceRef = ref();
const FileChoiceRef = ref();
const commodityTypes = ref([
	{
		icon: 'icon-commodity-yihangliangge',
		type: 1,
		content: '一行两个',
	},
	{
		icon: 'icon-yihangsange',
		type: 2,
		content: '一行三个',
	},
	{
		icon: 'icon-xuanzemokuai-daohanghengxianghuadong',
		type: 3,
		content: '横向滑动',
	},
]);

const openChoiceFileImage = () => {
	FileChoiceRef.value.openDialog();
};

const deleteItem = (index) => {
	props.datas.goodsList.splice(index, 1);
};

const choiceFile = (res: any) => {
	props.datas.tagStyle.src = res[0].visitRelativePath;
};

const choiceItem = (res: any) => {
	console.log('item: ', res);
	res.forEach((element) => {
		props.datas.goodsList.push(element);
	});
};

const openItemDialog = () => {
	ItemChoiceRef.value.openDialog();
};
</script>

<style scoped lang="scss">
.goodsShelvesstyle {
}

.commodityType {
	display: flex;
	justify-content: space-around;
	align-items: center;
	span {
		display: inline-block;
		width: 58px;
		height: 32px;
		text-align: center;
		line-height: 32px;
		background: #fff;
		border: 1px solid #ebedf0;
		color: #979797;
		margin: 0 1px;
		cursor: pointer;
		transition: all 0.5s;

		&:hover {
			border: 1px solid #155bd4;
			color: #155bd4;
		}

		&.active {
			border: 1px solid #155bd4;
			background-color: #e0edff;
			color: #155bd4;
		}
	}
}

.uploadImg {
	width: 100%;
	height: 40px;
	margin-top: 20px;
}
.tag {
	/* 图片 */
	display: flex;
	justify-content: space-around;
	align-items: center;
	.imag {
		width: 60px;
		height: 60px;
		border-radius: 5px;
		cursor: pointer;
		border: 1px dashed var(--el-border-color-darker);
		display: flex;
		justify-content: center;
		align-items: center;
		img {
			width: 100%;
			height: 100%;
			display: inline-block;
		}
	}
}
/* 商品列表 */
.imgBanner {
	padding: 6px 12px;
	margin: 16px 7px;
	border-radius: 2px;
	background-color: #fff;
	box-shadow: 0 0 4px 0 rgba(10, 42, 97, 0.2);
	display: flex;
	position: relative;

	/* 删除图标 */
	.el-icon-circle-close {
		position: absolute;
		right: -5px;
		top: -10px;
		cursor: pointer;
		font-size: 19px;
	}

	/* 图片 */
	.imag {
		width: 60px;
		height: 60px;
		border-radius: 5px;
		cursor: pointer;
		border: 1px dashed var(--el-border-color-darker);
		display: flex;
		justify-content: center;
		align-items: center;
		img {
			width: 100%;
			height: 100%;
			display: inline-block;
		}
		span {
			background: rgba(0, 0, 0, 0.5);
			font-size: 12px;
			position: absolute;
			left: 0px;
			bottom: 0px;
			display: inline-block;
			width: 100%;
			text-align: center;
			color: #fff;
			height: 20px;
			line-height: 20px;
		}
	}

	/* 图片字 */
	.imgText {
		width: 80%;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		padding-left: 20px;
		justify-content: space-between;
	}
}
.el-tabs--border-card {
	:deep(.el-tabs__content) {
		padding: 0px !important;
	}
	border: 0px;

	:deep(.el-tabs__header) {
		background-color: #d9d9d9 !important;
	}
}

:deep(.el-input-group__prepend) {
	padding: 0 0px;
}
:deep(.el-input-group__append) {
	padding: 0 0px;
	.el-checkbox {
		margin-left: 10px !important;
		margin-right: 10px !important;
	}
}

:deep(.el-input-group__prepend) {
	padding: 0px !important;
}

:deep(.el-input-group__append) {
	padding: 0px !important;
}

:deep(.el-color-picker__trigger) {
	padding: 0px;
}

:deep(.el-color-picker__color) {
	border: 0px;
}
</style>
